<?php
include_once 'Controlador/BL_Reporte.php';
include_once 'Controlador/Error.php';

class BL_ReporteGestor{
	
	private $arrObjArchReporte = null;
	
	private $arrReportes = null;
	private $arrApps = null;
	private $arrVentanas = null;
	private $arrReporteLineas = null;
	
	private $error = null;
	
	public function BL_ReporteGestor($arrObjArchReporte){		
		//Los datos se encuentran en el arreglo linea
		$this->arrObjArchReporte = $arrObjArchReporte;
		$this->arrReportes = array();
		$this->arrApps = array();
		$this->arrVentanas = array();
		$this->arrReporteLineas = array();
		$this->error = new Error(TipoError::SIN_ERRORES);
		
		$internalID = 0;
		foreach ($this->arrObjArchReporte as $objArchReporte) {
			$reporte = new BL_Reporte(
			$internalID,
			$objArchReporte->getNombre(),
			$objArchReporte->getLineas(),
			$this->arrApps,
			$this->arrVentanas
			);
			if(!$reporte->hayError()){					
				$this->arrReportes[$internalID] = array(
					'idReporteBD'=>0,
					'idReporteLocal'=>$internalID,
					'nomArch'=>$objArchReporte->getNombre(),
					'fecha'=>$reporte->getFecha(),
					'idComputer'=>$reporte->getIdComputer(),
					'user'=>$reporte->getUser(),
					'numLineas'=>$reporte->getNumLineas()
				);
				$internalID++;				
				
				$this->arrApps = $reporte->getArrApps();
				$this->arrVentanas = $reporte->getArrVentanas();
				$this->arrReporteLineas = array_merge(
					$this->arrReporteLineas,
					$reporte->getArrReporteLineas()
				);
			}							
			else{
				$this->error = $reporte->getError();
				break;					
			}
		}		
	}

	public function hayError() {
		return $this->error->hayError();
	}
	
	public function getError(){
		return $this->error;
	}	
	
	public function getArrReportes(){
		return $this->arrReportes;
	}
	
	public function getArrApps(){
		return $this->arrApps;
	}
	
	public function getArrVentanas(){
		return $this->arrVentanas;
	}
	
	public function getArrReporteLineas(){
		return $this->arrReporteLineas;
	}
	
}